package com.choco.jsondb.example;

import com.alibaba.fastjson.JSON;
import com.choco.jsondb.JSONDB;
import com.choco.jsondb.editor.Editor;

/*
Outputs:

[{"address":"China","name":"Steven"},{"address":"China","name":"Steven"}]
["array mode associated with key","array mode allow empty key"]
["null string cannot be a key","empty key is allowed","no key is allowed"]
["array mode associated with key","array mode allow empty key","null string cannot be a key","empty key is allowed","no key is allowed",{"address":"China","name":"Steven"},{"address":"China","name":"Steven"}]
 */
public class ArrayExample {
    public static void main(String[] args){
        JSONDB jsondb = new JSONDB.Builder().folder("jsondb").mode(JSONDB.ARRAY_MODE).connect();
        Editor editor = jsondb.edit();
        editor.put("person", new Person("Steven", "China"));
        editor.put("person", JSON.toJSONString(new Person("Steven", "China")));
        editor.put("string", "array mode associated with key");
        editor.put("string", "array mode allow empty key");
        editor.put("", "null string cannot be a key");
        editor.put(null, "empty key is allowed");
        editor.put("no key is allowed");
        editor.commit();

        System.out.println(jsondb.get("person"));
        System.out.println(jsondb.get("string"));
        System.out.println(jsondb.get());
        System.out.println(jsondb.getAll());
    }
}
